<?php
include ("./library.php");
$chk_sql = "select * from carpool.users where email = '".trim($_POST[id])."'";
$chk_result = pg_query($chk_sql);
$chk_data = pg_fetch_array($chk_result);

if($chk_data[0] == $_POST[id]){

    if($chk_data[3] == MD5($_POST[pass])){
        $_SESSION[user] = $chk_data[0];
        
        echo "<script>alert('Welcome!')</script>";
        echo "<script>parent.location.reload()</script>";
    }else{
        
        echo "<script>alert('Wrong password')</script>";
        echo '<script>history.back()</script>';
    }
}else{        
        echo "<script>alert('Email does not exist')</script>";
        echo '<script>history.back()</script>';
}
?>